package cn.aws360.boot.wechat.biz.mp.handler;

import cn.aws360.boot.wechat.biz.mp.builder.WxMpOutBuilder;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author junnan
 */
@Slf4j
@Component
public class WxMpEvent4FollowHandler implements WxMpMessageHandler {

    private final static String MSG_FOLLOW = "欢迎您关注，快来和我聊天吧~";

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage mpXmlMessage, Map<String, Object> context,
                                    WxMpService mpService, WxSessionManager wxSessionManager) {
        String event = mpXmlMessage.getEvent();

        if (WxConsts.EventType.SUBSCRIBE.equals(event)) {
            return WxMpOutBuilder.buildText(mpXmlMessage, MSG_FOLLOW);
        }

        return null;
    }

}
